<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>登录</title>
		<link rel="stylesheet" type="text/css" href="__API__/lib/css/swiper.min.css">
		<link rel="stylesheet" type="text/css" href="__API__/lib/css/mui.css?v=1">
		<link rel="stylesheet" type="text/css" href="__API__/lib/css/mobileSelect.css" />
		<link rel="stylesheet" href="__API__/lib/css/style.css">
		<script type="text/javascript" src="__API__/lib/js/jquery-1.11.0.min.js"></script>
		<script type="text/javascript" src="__API__/lib/js/mui.js"></script>
		<script src="__API__/lib/js/mobileSelect.js" type="text/javascript" charset="utf-8"></script>
		<script src="__API__/lib/js/city.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="__API__/lib/js/swiper.min.js"></script>
		<script type="text/javascript" src="__API__/lib/js/vue.min.js"></script>
		<script type="text/javascript" src="__API__/lib/js/common.js"></script>
		<script type="text/javascript" src="__API__/lib/js/index.js"></script>
	<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script></head>

	<body>
		<div class="register" id="app">
			<div class="registerinfo">
				<div class="registerinfo_con">
					<div class="logo"><img :src="logoImg" alt=""></div>
					<div style="width: 100%; text-align: center; color: #ccc">{{invite_code}}</div>
					<ul class="form_list">
						<li>
							<div class="icon"><img src="__API__/lib/images/l_icon1.png" alt=""></div><input type="tel"
								 v-model="mobile" placeholder="请输入手机号" />
						</li>
						<li>
							<div class="icon"><img src="__API__/lib/images/l_icon2.png" alt=""></div>
							<input type="number" name="" id="" v-model="code" placeholder="请输入短信验证码" />
							<button class="yzmcode" @click="getCode()" :disabled="disadles">{{massage}}</button>
						</li>
					</ul>
				</div>
				<div class="register_btn blue_btn" @click="onLogin">
					快捷登录
				</div>
				<div class="yzmlogin">
					<span @click="goDetail('register.html')">立即注册</span>
					<span @click="goDetail('login.html')">账号登录</span>
				</div>
			</div>
		</div>
		<script>
			var app = null;
			app = new Vue({
				el: '#app',
				data: {
					logoImg: "{:cache('logo')}",
					mobile: '',
					code: '',
					time: 60,
					disadles: false,
					massage: '获取验证码',
					invite_code:''
				},
				created: function() {
					var that = this;
					that.invite_code = localStorage.getItem('invite_code');
				},
				methods: {
					//获取验证码
					getCode() {
						let that = this;
						if(!that.mobile){
							return common.alert('请填写手机号',' ');
						}
						let setInter = setInterval(() => {
							that.time--;
							if (that.time <= 0) {
								that.massage = "获取验证码";
								that.disadles = false;
								clearInterval(setInter);

							} else {
								that.massage = "重新获取(" + that.time + ")";
								that.disadles = true;
							}
						}, 1000);
						axios
								.post('{:url("Member/captcha")}',{type:'quick_login',mobile:that.mobile})
								.then(res=>{
									if(res.data.code != 200){
										return common.alert(res.data.msg,' ')
									}else{
										return  common.showToast(res.data.msg,' ');
									}
								})
					},
					//登录
					onLogin() {
						let that = this;
						console.log('登录')
						let data = {
							mobile: that.mobile,
							captcha: that.code,
							invite_code:localStorage.getItem('invite_code')
						}
						if (data.mobile == '' || data.captcha == '') {
							return common.alert('账号或验证码不能为空',' ');
						}
						if(!common.validate.isPhone(data.mobile)){
							return common.alert('请输入正确的手机号',' ')
						}
						common.ajax("{:url('Member/quick_login')}", data, function(res) {
							common.showToast(res.msg);
							if (res.code == 200) {
								 localStorage.setItem('openid',res.data.openid);
								localStorage.setItem('member_id',res.data.id)
								localStorage.setItem('token',res.data.token)
								setTimeout(function() {
									common.openUrl("{:url('index')}");
								}, 1000)
							}else if(res.code == 201){
								localStorage.setItem('member_id',res.data.id)
								localStorage.setItem('token',res.data.token)
								setTimeout(function() {
									common.openUrl("{:url('index')}");
								}, 1000)
							}

						})
					},
					goDetail(url) {
						common.openUrl(url);
					}
				}
			})
		</script>
	</body>

</html>
